<?php
class Karyawan_history_cuti_model extends MY_Model {
	
    function Karyawan_history_cuti_model(){
        parent::MY_Model();
        $this->load->database();
        $this->table_name = "karyawan_history_cuti";
    }
    
    /**
     * 
     * @param $id
     */
    function select_by_id($id){
    	return $query = $this->db->get_where($this->table_name, array('kary_cuti' => $id));
    }
    
	function getHistory($kary_id, $key=false, $where=false, $limit=10, $offset=0, $orderby=false){
 		/**
 		 * THE SQL:
 		 * 		SELECT * FROM `karyawan_history_cuti` WHERE kary_id='$kary_id'
 		 */
 		if ($key){
 			$key = "AND (
				kary_cuti_jenis 		LIKE '%$key%' OR
				kary_cuti_tgl_mulai 	LIKE '%$key%' OR
				kary_cuti_tgl_selesai 	LIKE '%$key%' OR 
				kary_cuti_keterangan 	LIKE '%$key%' OR
				kary_id 				LIKE '%$key%')";
 		}
 		
 		if ($where) { $where = " AND $where"; }
 	
 		if ($orderby){ $orderby = "ORDER BY $orderby"; }
 		
 		$limit = " LIMIT $offset,$limit ";  
 		
    	return $this->db->query(
    		"SELECT *
 		  	FROM ". $this->table_name ."
 		  	WHERE kary_id='$kary_id'
 		  		$key 
 		  		$where
 		  		$orderby 
 		  		$limit");
    }
}